﻿@using Lavka.Core
@using Lavka.Models
@model Lavka.Models.Orders

@{
    ViewBag.Title = "Детальная информация о заказе";
}
<p>
    @Html.ActionLink("Редактировать", "Edit", new { id = Model.OrderId }) |
    @Html.ActionLink("К списку", "Index")
</p>
<div class="panel ui-corner-all">
    <h2>Заказ № @Model.OrderId от @Model.OrderDate</h2>
    <table style="border-spacing: 5px;">
    <tr>
        <td>
            <div class="header">Покупатель</div>
            <table style="border-spacing: 5px;">
            <tr>
            <td>
                <div class="display-label">Имя</div>
            </td>
            <td>
                <div class="display-field">@Model.Customers.Name</div>
            </td>
            <td>
                <div class="display-label">Телефон</div>
            </td>
            <td>
                <div class="display-field">@Model.Customers.Phone</div>
            </td>
            </tr>

            <tr>
            <td>
                <div class="display-label">Email</div>
            </td>
            <td>
                <div class="display-field">@Model.Customers.Email</div>
            </td>
            <td>
                <div class="display-label">Адрес доставки</div>
            </td>
            <td>
                <div class="display-field">@Model.Customers.DeliveryAddress</div>
            </td>
            </tr>


            <tr>
            <td>
                <div class="display-label">Ключ покупателя</div>
            </td>
            <td>
                <div class="display-field">@Html.DisplayFor(model => model.OrderKey)</div>
            </td>
            <td>
                <div class="display-label">Дата заказа</div>
            </td>
            <td>
                <div class="display-field">@Html.DisplayFor(model => model.OrderDate)</div>
            </td>
            </tr>

            <tr>
            <td>
                <div class="display-label">Самовывоз</div>
            </td>
            <td>
                <div class="display-field">@Html.DisplayFor(model => model.Pickup)</div>
            </td>
            <td>
                <div class="display-label">Выполнение</div>
            </td>
            <td>
                <div class="display-field">@Html.DisplayFor(model => model.Completed)</div>
            </td>
            </tr>   
            </table>
        </td>
    </tr>
    <tr>
    <td>
    <div class="roundedTable">    
    <table id="productsTable" class="productsTable">
        <tr>
            <th>
                Наименование
            </th>
            <th>
                Артикул
            </th>
            <th>
                Производитель
            </th>
            <th>
                Категория
            </th>
            <th>
                Цена
            </th>
            <th>
                Кол-во
            </th>
            <th>
                Сумма
            </th>
        </tr>

          @foreach (var item in Model.OrderedProducts)
          {
            var product = item.Products;
              var price = ProductsHelper.GetProductPrice(product, new LavkaDbEntities());
            <tr>           
                <td>
                    @if (!string.IsNullOrEmpty(product.Name))
                    {
                        @Html.ActionLink(product.Name, "Details","Products", new { id = item.ProductId }, null)
                    }
                </td>
                <td>
			        @product.Reference
                </td>
                <td>
			        @product.Brands.Name
                </td>
                <td>
			        @product.Caterories.Name
                </td>
                <td>
                    <span class="table-price">@String.Format("{0:0.00}", price)</span>
                </td>
                <td>
                    <span class="table-price">@item.Number</span>
                </td>
                <td>
                    <span class="table-price">@String.Format("{0:0.00}", Convert.ToDecimal(price) * item.Number)</span>
                </td>
            </tr>              
          }
            <tr>
                <td colspan="7" style="text-align: right;">
                Всего: @OrdersHelper.GetOrderSumPrice(Model.OrderId, new LavkaDbEntities())
                </td>
            </tr>
    </table>
    </div>
    </td>
    </tr>
    <tr>
        <td style="padding: 5px;">
            <div class="header">Описание заказа</div>
            <div class="display-field">
                @if (!string.IsNullOrEmpty(Model.Description))
                {
                    @Html.DisplayFor(model => model.Description)
                }
                else
                {
                    @:Описание отсутствует.
                }
                
            </div>        
        </td>
    </tr>
    </table>
</div>
